<!doctype html>
<html lang="zh-cn">
<head>
{% include "tdm_include_head_template.html" %}

<script type="text/javascript">
function refresh_ctminfo() {
  $.getJSON('/tdm/json/acard/venuesync/{{view_city.name}}/', function (data) {
    var toattend = 0;
    var attend = 0;
    $.each(data, function(i, ctminfo) {
      console.log(ctminfo);
      var ctmdev_status = '';
      if (!ctminfo.status) {
        ctmdev_status = '<span class="badge badge-danger"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></span> ';
      } else {
        for (var cr in ctminfo.crstatus) {
          //console.log(cr_list[cr]);
          if (ctminfo.crstatus[cr].status==false) {
            ctmdev_status = '<span class="badge badge-warning"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></span> ';
          }
        }
        if (ctmdev_status=='') {
          ctmdev_status = '<span class="badge badge-success"><span class="glyphicon glyphicon-ok" aria-hidden="true"></span></span> ';
        }
      }
      ctmdev_newinfo = '<td>'+ctmdev_status+'<a title="'+ctminfo.service_name+'">'+ctminfo.venue+'</a></td>';
      ctmdev_newinfo += '<td><a href="/tdm/acard/'+ctminfo.city+'/'+ctminfo.venue+'/'+ctminfo.ctmdev+'">'+ctminfo.ctm+'</a></td>';
      ctmdev_newinfo += '<td>'+fixup_master_slaver(ctminfo.master_slaver, ctminfo.ip_100)+'</td>';
      ctmdev_newinfo += '<td>'+fixup_crstatus(ctminfo.crstatus)+'</td>';
      ctmdev_newinfo += '<td>'+sec2date(ctminfo.class_date)+'<br/>'+ctminfo.ctm_date+'</td>';
      ctmdev_newinfo += '<td>'+fixup_attend_percent(ctminfo.attend,ctminfo.toattend)+'</td>';
      ctmdev_newinfo += '<td>'+fixup_noval(ctminfo.cpu)+'%</td>';
      ctmdev_newinfo += '<td>'+fixup_noval(ctminfo.memory)+'%</td>';
      ctmdev_newinfo += '<td>'+fixup_noval(ctminfo.disk)+'%</td>';
      ctmdev_newinfo += '<td>'+fixup_version(ctminfo.app_ver,ctminfo.cli_ver)+'</td>';
      ctmdev_newinfo += '<td>'+fixup_onoff(ctminfo.app_live)+'</td>';
      ctmdev_newinfo += '<td>'+fixup_onoff(ctminfo.port_9100)+'</td>';
      ctmdev_newinfo += '<td>'+fixup_onoff(ctminfo.port_3306)+'</td>';
      //console.log(ctmdev_newinfo);
      $("#"+ctminfo.ctmdev).html(ctmdev_newinfo);
      if (typeof(ctminfo.toattend) != "undefined" && typeof(ctminfo.attend) != "undefined") {
        if (ctminfo.ip_100) {
          toattend += ctminfo.toattend;
          attend += ctminfo.attend;
        }
      }
    });
    $("span#attend_count").html("考勤数据:"+attend+"("+toattend+")");
  });
}
$(function() {
  sidebar_nav_clone();
  setInterval(function() {
    refresh_ctminfo();
  }, 180000);
  refresh_ctminfo();
});
</script>

</head>

<body class=" theme-blue">
{% include "tdm_include_navbar_template.html" %}

<div class="sidebar-nav">
  <ul id="city_jxd">
  {% for city in city_all %}
  <li>
    <a href="#" data-target=".{{city.name}}-menu" class="nav-header collapsed" data-toggle="collapse" aria-expanded="false">
      <i class="fa fa-fw fa-bars"></i>
      {{city.name}}
      {% if city.warning_nr %}
      <span class="badge badge-warning">{{city.warning_nr}}</span>
      {% endif %}
      {% if city.alert_nr %}
      <span class="badge badge-danger">{{city.alert_nr}}</span>
      {% endif %}
      <i class="fa fa-collapse"></i>
    </a>
  </li>
  <li>
    <ul class="{{city.name}}-menu nav nav-list collapse {% ifequal view_city city.name %}in{% endifequal %}">
      {% for venue in city.venues %}
      {% if not venue.disabled %}
      <li>
        <a href="/tdm/acard/{{city.name}}/{{venue.name}}">
          <span class="fa fa-caret-right"></span>
          {{venue.name}}
          {% if venue.warning_nr %}
          <div class="pull-right">
            <span class="badge badge-warning">{{venue.warning_nr}}</span>
          </div>
          {% endif %}
          {% if venue.alert_nr %}
          <div class="pull-right">
            <span class="badge badge-danger">{{venue.alert_nr}}</span>
          </div>
          {% endif %}
        </a>
      </li>
      {% endif %}
      {% endfor %}
    </ul>
  </li>
  {% endfor %}
  </ul>
</div>

<div class="content">
  <div class="header">
    <a class="btn btn-primary btn-jxd" rol="button" href="/tdm/acard/{{view_city.name}}/">
      <span class="glyphicon glyphicon-circle-arrow-right"></span>
      {{view_city.name}}
      <span id="ctmdev_count">工控机数量:{{view_venue_ctmdev_list|length}}</span>
      <span id="attend_count"></span>
    </a>
    <ul class="nav nav-tabs" role="tablist">
      {% for server in server_list %}
      <li role="presentation" {% ifequal server.name view_server %}class="active"{% endifequal %}>
        <a href="/tdm/acard/{{view_city.name}}/{{view_jxd}}/{{server.name}}">{{server.name}}
        {% if server.warning_nr %}
        <span class="badge badge-warning">{{server.warning_nr}}</span>
        {% endif %}
        {% if server.alert_nr %}
        <span class="badge badge-danger">{{server.alert_nr}}</span>
        {% endif %}
        </a>
      </li>
      {% endfor %}
    </ul>
  </div>
  <div class="table-responsive">
    <table class="table table-hover">
      <tr>
        <th>教学点</th>
        <th>中控机</th>
        <th>主备</th>
        <th>考勤机状态</th>
        <th>考勤时间</th>
        <th>考勤数据</th>
        <th>处理器</th>
        <th>内存</th>
        <th>磁盘</th>
        <th>程序版本</th>
        <th>程序存活</th>
        <th>端口9100</th>
        <th>端口3306</th>
      </tr>
      {% for ctmdev_log in view_venue_ctmdev_list %}
      <tr id="{{ctmdev_log.ctmdev}}">
        <td>{{ctmdev_log.venue}}</td>
        <td><a href="/tdm/acard/{{view_city.name}}/{{ctmdev_log.venue}}/{{ctmdev_log.ctmdev}}">{{ctmdev_log.ctmdev}}</a></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
      </tr>
      {% endfor %}
      {% if view_venue_log|length_is:"0" %}
      <tr><td colspan="12" align="center">无设备</td></tr>
      {% endif %}
    </table>
  </div>
  <div class="item-content">
  {% include "tdm_include_footer_template.html" %}
  </div>
</div>
</body>
</html>
